public class Demo {
    public int minSubArrayLen(int target, int[] nums){
        int left = 0;
        int right = 0;
        int sum = 0;
        int len = 0;
        int newlen = nums.length + 1;
        while (right < nums.length){
            sum += nums[right];
            while (sum >= target){
                len = right - left + 1;
                newlen = Math.min(len,newlen);
                sum -= nums[left];
                left++;
            }
            right++;
        }
        return newlen == nums.length + 1 ? 0 : newlen;
    }
}
